// components/Tabs/index.js
Component({
  // 开启多插槽
  options: {
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    data: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentTabIndex: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {

    handleTabChange(event) {
      const index = event.currentTarget.dataset.index
      // if (index === this.data.currentTabIndex) {
      //   return
      // }
      // console.log(this.data.active);
      this.setData({
        currentTabIndex: index
      })
      this.triggerEvent("change", {
        index
      })
    },
    handleTouchMove: function (event) {
      const direction = event.direction
      const currentTabIndex = this.data.currentTabIndex
      const targetTabIndex = currentTabIndex + direction
      if (targetTabIndex < 0 || targetTabIndex > this.data.data.length - 1) {
        return
      }
      const customEvent = {
        currentTarget: {
          dataset: {
            index: targetTabIndex
          }
        }
      }
      this.handleTabChange(customEvent)
    }
  }
})